package com.key.modules.service.impl;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.key.modules.dto.CustomerReDTO;
import com.key.modules.entity.CustomerSt;
import com.key.modules.mapper.CustomerStMapper;
import com.key.modules.service.CustomerReService;
import com.key.modules.vo.CustomerReVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@Service
@Slf4j
public class CustomerReServiceImpl implements CustomerReService {

    @Autowired
    CustomerStMapper customerStMapper;
    @Autowired
    RedisTemplate redisTemplate;

    @Override
    public int createCustomerStatement(CustomerSt customerSt) {
        log.info("进入createCustomerStatement方法，创建对账单"+
                "，StatementNumber = "+customerSt.getStatementNumber()+
                "，CustomerName = "+customerSt.getCustomerName()+
                "，BillingTime = "+customerSt.getBillingTime()+
                "，BillingStatus = "+ customerSt.getBillingStatus()+
                "，InvoiceStatus = "+ customerSt.getInvoiceStatus()+
                "，AmountReceivable = "+customerSt.getAmountReceivable()+
                "，AbnormalState = "+customerSt.getAbnormalState()+
                "，PaybackDate = "+customerSt.getPaybackDate()+
                "，CreationTime = "+ customerSt.getCreationTime()
        );
        //往数据库添加数据
        int resultInt=customerStMapper.insertCustomerSt(customerSt.getStatementNumber(),customerSt.getCustomerName(),customerSt.getBillingTime(),
                customerSt.getBillingStatus(), customerSt.getInvoiceStatus(),customerSt.getAmountReceivable(),
                customerSt.getAbnormalState(),customerSt.getPaybackDate(),customerSt.getCreationTime());

        log.info("createCustomerStatement方法结束");
        return resultInt;
    }

    @Override
    public Map<String, Object> findCustomerReceivable(CustomerReDTO customerReDTO) {
        log.info("进入findCustomerReceivable方法，查找信息（支持高级搜索）"+
                "，CurrentPage = "+customerReDTO.getCurrentPage()+
                "，PageSize = "+customerReDTO.getPageSize()+
                "，CustomerName = "+customerReDTO.getCustomerName()+
                "，OrderTime = "+customerReDTO.getOrderTime()+
                "，BillingStatus = "+customerReDTO.getBillingStatus()
        );
        //设置paage分页查询
        Page<CustomerReVO> page=new Page<>(customerReDTO.getCurrentPage(),customerReDTO.getPageSize());
        Page<CustomerReVO> reVOPage= customerStMapper.selectCustomerRe(page,customerReDTO.getCustomerName(),customerReDTO.getOrderTime(),
                customerReDTO.getWaybillNo(),customerReDTO.getBillingStatus());
        //将获取的page里的total与数据返回
        List<CustomerReVO> voList=reVOPage.getRecords();
        Map<String,Object> resultMap=new HashMap<>();
        resultMap.put("data",voList);
        resultMap.put("total",(int)reVOPage.getTotal());
        log.info("findCustomerReceivable方法结束返回数据");
        return resultMap;
    }
}
